﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Rw.Core.Common;
using System.IO;
using System.Threading.Tasks;
using System;
using WH.Common.Config;
using WH.Common.Helper;
using WH.WebApi.Controllers;
using WH.Services.IServices.IRemoveWatermark;
using WH.Contracts.RemoveWatermark;
using Rw.Core.Common.Paging;
using Rw.Core.Document;
using System.Data;
using Microsoft.AspNetCore.Authorization;

namespace WH.WebAPI.Controllers.RemoveWatermark
{
    /// <summary>
    ///视频去水印
    /// </summary>
    [Route("RemoveWatermark"), ApiController]
    public class RemoveWatermarkController : BaseController
    {
        private IRemoveWatermarkService _removeWatermarkService;
        private readonly IConfigurationCenter _configuration;
        public RemoveWatermarkController(IRemoveWatermarkService removeWatermarkService, IConfigurationCenter configuration)
        {
            _removeWatermarkService = removeWatermarkService;
            _configuration = configuration;

        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpPost("Save")]
        [AllowAnonymous]
        public async Task<ResultResponse<string>> RemoveWatermarkFileSave([FromBody] RemoveWatermarkInputDto parm)
        {
            var result = await _removeWatermarkService.RemoveWatermarkSaveAsync(parm);
            return Success<string>(result);
        }
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="ids">ID1,ID2</param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ResultResponse> RemoveWatermarkDelete([FromBody] string[] ids)
        {
            bool flag = await _removeWatermarkService.RemoveWatermarkDeleteAsync(ids);

            return flag ? Success("删除成功") : Error("删除失败");
        }

        /// <summary>
        /// 分页检索
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("List")]
        public async Task<ResultResponse<IPagedList<RemoveWatermarkOutputDto>>> RemoveWatermarkListAsync([FromQuery] RemoveWatermarkFilterDto parm)
        {
            var list = await _removeWatermarkService.GetRemoveWatermarkPageListAsync(parm);

            return Success(list);
        }
        /// <summary>
        /// 导出
        /// </summary>
        /// <returns></returns>
        [HttpGet("Export")]
        public async Task<ActionResult> DataExport([FromQuery] RemoveWatermarkFilterDto parm)
        {
            var result = await _removeWatermarkService.DataExportAsync(parm);
            var filename = $"列表-{DateTime.Now:yyyyMMddHHmm}.xls";
            var dataTable = TableHelper.FromEntityWithPropertyDescription(result);
            var excel = ExcelHelper.WriteBytes(new DataTable[] { dataTable }, filename, true);
            Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
            return File(excel, "application/vnd.ms-excel", filename);
        }
    }
}

